import { request } from '@/utils/request'
import type { User, Code, UserInfo, PatientList, Patient } from '@/types/user'
// 发送请求
const loginByPassword = (mobile: string, password: string) =>
  request<User>('/login/password', 'POST', {
    mobile,
    password
  })

const getMobileCode = (mobile: string, type: Code) => {
  request('/code', 'GET', {
    mobile,
    type
  })
}

const loginByCode = (mobile: string, code: string) =>
  request<User>('/login', 'POST', {
    mobile,
    code
  })
const getUser = () => request<UserInfo>('/patient/myUser', 'GET')
// 获取家庭档案(患者)列表

const getPatientList = () => request<PatientList>('/patient/mylist', 'GET')
// 添加患者信息
const addPatient = (patient: Patient) =>
  request('/patient/add', 'POST', patient)
// 编辑0患者信息
const editPatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)

const delPatient = (id: string) => request(`/patient/del/${id}`, 'DELETE')
// 请求患者信息

const getPatientDetail = (id: string) => request<Patient>(`/patient/info/${id}`)

export {
  loginByPassword,
  getMobileCode,
  loginByCode,
  getUser,
  getPatientList,
  addPatient,
  editPatient,
  delPatient,
  getPatientDetail
}
